﻿// wwwroot/site.js
window.openFolderDialog = async function () {
    return new Promise((resolve, reject) => {
        const inputElement = document.createElement('input');
        inputElement.type = 'file';
        inputElement.webkitdirectory = true;
        inputElement.directory = true;
        inputElement.accept = '/';

        inputElement.addEventListener('change', async (event) => {
            const files = event.target.files;
            if (files.length > 0) {
                const firstFile = files[0];
                const webkitRelativePath = firstFile.webkitRelativePath || firstFile.name;
                const folderPath = webkitRelativePath.split('/').slice(0, -1).join('/');
                resolve(folderPath);
            } else {
                resolve(null);
            }
        });

        inputElement.click();
    });
}